package cn.edu360.streaming.utils

import java.net.URI

import org.apache.hadoop.conf.Configuration
import org.apache.hadoop.fs.{FileSystem, FileUtil, Path}

/**
  * 文件合并工具
  * wzxjava@126.com
  * Created by wangzhixuan on 2017/05/18 19:31
  */
object HdfsUtil {

  /**
    * 合并文件
    *
    * @param srcPath
    * @param dstPath
    */
  def merge(srcPath: String, dstPath: String): Unit = {
    val conf = new Configuration()
    val hdfs = FileSystem.get(URI.create(srcPath), conf)
    if (hdfs.exists(new Path(dstPath)))
      hdfs.delete(new Path(dstPath), false)
    FileUtil.copyMerge(hdfs, new Path(srcPath), hdfs, new Path(dstPath), true, conf, null)
  }

}
